package com.everydayflash.cart.patterns {
	import com.everydayflash.cart.core.AbstractSketch;
	
	import flash.display.Shape;	

	/**
	 * @author bartekd
	 */
	public class SquarePattern extends AbstractSketch {
		
		private var squares:Vector.<Shape>;

		override protected function init():void {
			var sq:Number = 20;
			var mr:Number = 4;
			
			var r:Number = mr;
			var c:Number = mr;
			
			squares = new Vector.<Shape>();

			while(r < sh) {
				c = mr;
				while(c < sw) {
					var sqs:Shape = new Shape();
					sqs.graphics.beginFill(randomColor());
					sqs.graphics.drawRect(-sq/2,-sq/2, sq, sq);
					addChild(sqs);
					sqs.x = c + sq/2;
					sqs.y = r + sq/2;
					squares.push(sqs);
					c += sq + mr;
				}
				r += sq + mr; 
			}
			
			var i:Number = 0;
			for each (var s : Shape in squares) {
				s.rotation = i;
				s.scaleX = s.scaleY = 1 + Math.random() * 2;
				i += .2;
			}
			
//			filters = [new BlurFilter(32, 32, 3)];
		}
		
		private function randomColor():uint {
			return Math.random() * 0x111111;
		}

		override protected function draw():void {
			for each (var s : Shape in squares) {
				s.rotation += 3;
			}
		}
	}
}
